home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
winword
/
cpretty2.zip
/
prettyc2.txt
Wrap
Text File
|
1994-04-07
|
12KB
|
306 lines
'Free WordBasic Macro to make C programming code look nicer when printed.
'(for Word for Windows 6)
' Instructions: open this document in MS-Word for Windows, select the whole document
' and copy it to the clipboard. Open a new macro (i.e. the 'Tools' menu, 'Macro...'), call it
' whatever you like. Delete the 'Sub Main' and 'End Sub' lines, so you have a blank page,
' then Paste this document into that macro, and voila! there you have it.
'
' Pretty C Mk II
'
' Howard Jones, 1994 (ha.jones@ic.ac.uk)
' Modified from PrettyC by
' Phillip Ryan, DSTO Materials Research Laboratory, Melbourne, Australia
' (ryanph@mrl.dsto.gov.au)
' Now supports C++ comments, Word 6.0 (no longer Word 2.x - Sorry!)
' and extra C++ reserved words.
' Also altered order so there are no keyword-in-comment problems
' and added subroutine structure so it is a *little* neater :)
' [It should be fairly trivial to port back to Word 2.x, BTW ]
' [EditFind to EditSearch, and EditFindFont to EditSearchChar, mostly]
'
' This is a free macro - if your fix any bugs, add any more goodies
' or otherwise improve this macro, please send me a copy (email if poss)
' (also, one for Phillip Ryan, too - it was his baby!)
'
' Howard Jones, 12 Fountains Garth, Bracknell, Berkshire, RG12 7RH, UK.
'
' It does no actual code formatting - for that, use GNU Indent
'
' ********************************************************
' CAUTION!
' This will clear any formatting in the document before it starts!
' Don't do any special prettifying until *after* running this!
' ********************************************************
Sub MAIN
StartOfDocument
' first, flush all the formatting info - for a clean sheet
EditSelectAll
ResetChar
' do the actual formatting
Call FormatCComments
Call FormatCPlusPlusComments
Call FormatDirectives
Call FormatANSIKeys
Call FormatStdioKeys
Call FormatCPlusPlusKeys
'Notify we're finished, and clear up
Beep
Print "Pretty C is finished"
End Sub
'*******************************************************************************
' Subroutine to format the C++ style comments
Sub FormatCPlusPlusKeys
Print "Formatting C++ Keywords"
' For the first set of words, make the format of the replaced text be bold only.
EditReplaceFont .Bold = 1, .Italic = 0, .Underline = 0, .Strikethrough = 0
' Start doing the replacing.
EditReplace .Find = "virtual", .Replace = "virtual", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "class", .Replace = "class", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "private:", .Replace = "private:", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "public:", .Replace = "public:", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
StartOfDocument
EditReplace .Find = "public", .Replace = "public", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "inline", .Replace = "inline", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "protected:", .Replace = "protected:", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "friend", .Replace = "friend", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
End Sub
'*******************************************************************************
' Subroutine to format the C++ style comments
Sub FormatCPlusPlusComments
Print "Formatting C++ Comments"
StartOfDocument
' Look for the normal comment string delimiter of C.
EditFindClearFormatting
EditFindFont .Italic = 0
EditFind .Find = "//", .Format = 1
' Keep on searching for comment blocks.
While EditFindFound()
ExtendSelection
EditFind .Find = "^p"
FormatFont .Italic = 1, .Bold = 0
Cancel
' To ensure that the next found character is in the _next_ comment block,
' we set the findchar type to italic _off_. (Since otherwise the insertion
' point always remains at the start of the last selection.)
StartOfDocument
EditFind .Find = "//", .Format = 1
Wend
StartOfDocument
End Sub
'*******************************************************************************
' Subroutine to format the C style comments
Sub FormatCComments
Print "Formatting C Comments"
' Now, to format the comments.
StartOfDocument
' Look for the normal comment string delimiter of C.
EditFindClearFormatting
EditFindFont .Italic = 0
EditFind .Find = "/*", .Format = 1
' Keep on searching for comment blocks.
While EditFindFound()
ExtendSelection
EditFind .Find = "*/"
FormatFont .Italic = 1, .Bold = 0
Cancel
' To ensure that the next found character is in the _next_ comment block,
' we set the findchar type to italic _off_. (Since otherwise the insertion
' point always remains at the start of the last selection.)
StartOfDocument
EditFind .Find = "/*", .Format = 1
Wend
StartOfDocument
End Sub
'*******************************************************************************
' Subroutine to format the pre-processor keywords
Sub FormatDirectives
Print "Formatting Pre-processor Directives"
' For the last set, the C pre-processor directives, make the format bold-italic only.
EditReplaceFont .Bold = 1, .Italic = 1, .Underline = 0, .Strikethrough = 0
EditReplace .Find = "#include", .Replace = "#include", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "#define", .Replace = "#define", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "#ifdef", .Replace = "#ifdef", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "#error", .Replace = "#error", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "#ifndef", .Replace = "#ifndef", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "#if", .Replace = "#if", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "#else", .Replace = "#else", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "#elif", .Replace = "#elif", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "#endif", .Replace = "#endif", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "#pragma", .Replace = "#pragma", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
End Sub
'*******************************************************************************
' Subroutine to format the stdio keywords
Sub FormatStdioKeys
Print "Formatting stdio Functions/Types"
'For this next set, which is a small subset of the standard libraries, make the replaced text
'format be italic only.
EditReplaceFont .Bold = 0, .Italic = 1, .Underline = 0, .Strikethrough = 0
StartOfDocument
EditReplace .Find = "main", .Replace = "main", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "printf", .Replace = "printf", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "fprintf", .Replace = "fprintf", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "scanf", .Replace = "scanf", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "fscanf", .Replace = "fscanf", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "getc", .Replace = "getc", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "getch", .Replace = "getch", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "getchar", .Replace = "getchar", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "putc", .Replace = "putc", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "putch", .Replace = "putch", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "putchar", .Replace = "putchar", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "FILE", .Replace = "FILE", .Format = 1, .WholeWord = 1, .MatchCase = 1, .ReplaceAll
StartOfDocument
End Sub
'*******************************************************************************
' Subroutine to format all the ANSI Keywords in the document
Sub FormatANSIKeys
Print "Formatting ANSI C Keywords"
' For the first set of words, make the format of the replaced text be bold only.
EditReplaceFont .Bold = 1, .Italic = 0, .Underline = 0, .Strikethrough = 0
' Start doing the replacing.
EditReplace .Find = "float", .Replace = "float", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "long", .Replace = "long", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "int", .Replace = "int", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "double", .Replace = "double", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "if", .Replace = "if", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "then", .Replace = "then", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "else", .Replace = "else", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "while", .Replace = "while", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "until", .Replace = "until", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "repeat", .Replace = "repeat", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "return", .Replace = "return", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "break", .Replace = "break", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "case", .Replace = "case", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "switch", .Replace = "switch", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "repeat", .Replace = "repeat", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "register", .Replace = "register", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "volatile", .Replace = "volatile", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "union", .Replace = "union", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "typedef", .Replace = "typedef", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "struct", .Replace = "struct", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "auto", .Replace = "auto", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "const", .Replace = "const", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "continue", .Replace = "continue", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "default", .Replace = "default", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "enum", .Replace = "enum", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "extern", .Replace = "extern", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "goto", .Replace = "goto", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "short", .Replace = "short", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "signed", .Replace = "signed", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "unsigned", .Replace = "unsigned", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "sizeof", .Replace = "sizeof", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "static", .Replace = "static", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "void", .Replace = "void", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
EditReplace .Find = "char", .Replace = "char", .Format = 1, .WholeWord = 1, .ReplaceAll
StartOfDocument
End Sub